<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <style>
        html {
            font-size: 20px !important;
        }

        .aui-title {
            color: #303030 !important;
            font-size: 0.8rem !important;
        }

        .aui-pull-right {
            color: #2780e8 !important;
            font-size: 0.7rem !important;
        }
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav aui-bar-light hd" id="app" v-cloak>
        <a id="back" class="aui-pull-left aui-btn">
            <img src="../image/icon_back.png" style="width: 0.45rem;height: 0.8rem;margin-left: 0.7rem;" alt="">
        </a>
        <div class="aui-title">
            医嘱
        </div>

        <a class="aui-pull-right aui-btn" @click="saveAdvice">
            保存
        </a>
    </header>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/hb.js"></script>
<script type="text/javascript" src="../script/vue.js"></script>
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript">
    apiready = function () {
        hb_ready()

        api.addEventListener({
            name: 'save_changyongyizhu'
        }, function (ret, err) {
            // alert(JSON.stringify(ret.value));
            app.content = ret.value.content
            app.index = ret.value.index
        });

        api.addEventListener({
            name: 'save_yizhu'
        }, function (ret, err) {
            app.content = ret.value.content
            app.index = ret.value.index
        });
        hb_openframeby_auto('yizhu_frm', api.pageParam)
    };

    var app = new Vue({
        el: "#app",
        data: {
            content: "",
            index: -1,
        },
        methods: {
            saveAdvice: function () {
                api.sendEvent({
                    name: 'medicalAdvice',
                    extra: {
                        content: this.content
                    }
                });
                api.closeWin()
            }
        },
    })

    function baocun_yizhu() {
        if (app.index == 0) {
            post_ajax("doctor/advice/save", {
                userId: 1,
                content: app.content,
                remark: "医嘱备注",
            }, function (res, err) {
                if (res) {
                    toast("保存为常用医嘱成功")
                    api.sendEvent({
                        name: 'chuandi_yizhu',
                        extra: {
                            content: app.content,
                        }
                    });
                    setTimeout(function () {
                        api.closeWin()
                        app.$nextTick(function () {
                            hb_init_openwinby_click();
                        })
                    }, 500)
                } else {
                    alert("网络不通畅，请稍后再试！")
                }
            })
        } else if (app.index == 1) {
            api.sendEvent({
                name: 'chuandi_yizhu',
                extra: {
                    content: app.content,
                }
            });

            app.$nextTick(function () {
                hb_init_openwinby_click();
            })
            api.closeWin()
        }
    }
</script>

</html>